<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${package.Mapper}.${table.mapperName}">

    <sql id="Base_Column_List">
        <#list table.fields as field>${field.annotationColumnName}<#if field_has_next>,</#if></#list>
    </sql>

    <select id="getList" resultType="${package.Entity}.${entity}">
        select
        <include refid="Base_Column_List"/>
        from ${table.name}
        <where>
            <#list table.fields as field>
            <if test="${field.propertyName} != null">
                AND ${field.annotationColumnName} = ${r'#{'}${field.propertyName}${r'}'}
            </if>
            </#list>
        </where>
    </select>

    <insert id="insertData" parameterType="${package.Entity}.${entity}" useGeneratedKeys="true" keyProperty="id">
        insert into ${table.name}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <#list table.fields as field>
            <if test="${field.propertyName} != null">${field.annotationColumnName},</if>
            </#list>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <#list table.fields as field>
                <if test="${field.propertyName} != null">${r'#{'}${field.propertyName}${r'}'},</if>
            </#list>
        </trim>
    </insert>

    <update id="update" parameterType="${package.Entity}.${entity}">
        update ${table.name}
        <trim prefix="SET" suffixOverrides=",">
            <#list table.fields as field>
            <#if field.propertyName != "id" && field.propertyName != "createTime">
            <if test="${field.propertyName} != null">${field.annotationColumnName} = ${r'#{'}${field.propertyName}${r'}'},</if>
            </#if>
            </#list>
        </trim>
        where id = ${r'#{id}'}
    </update>

    <delete id="deleteById" parameterType="Long">
        delete from ${table.name} where id = ${r'#{id}'}
    </delete>

    <select id="getPage" resultType="${package.Entity}.${entity}">
        select
        <include refid="Base_Column_List"/>
        from ${table.name}
        <where>
        <#list table.fields as field>
            <#if field.propertyName != "id" && field.propertyName!= "createTime" && field.propertyName!= "updateTime">
            <if test="queryParams.${field.propertyName} != null and queryParams.${field.propertyName} != ''">
                ${field.annotationColumnName} = ${r'#{queryParams.'}${field.propertyName}${r'}'}
            </if>
            </#if>
        </#list>
        </where>
        order by create_time desc
    </select>
</mapper>